#include "bor_mod_dialog.h"
#include "ui_bor_mod_dialog.h"
#include"QDate"
#include"QKeyEvent"
bor_mod_dialog::bor_mod_dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::bor_mod_dialog),
    flag(false)
{
    ui->setupUi(this);
    ui->comboBox_3->addItems({"未归还","已归还","丢失","毁坏","破损"});
}

bor_mod_dialog::~bor_mod_dialog()
{
    delete ui;
}

void bor_mod_dialog::printfData()
{
    ui->lineEdit_stu_number_3->setText( this->student[0]);
    ui->lineEdit_stu_name_3->setText(this->student[1]);
    ui->lineEdit_stu_class_3->setText(this->student[3]);

    ui->lineEdit_book_number_3->setText(book[0]);
    ui->lineEdit_book_name_3->setText(book[1]);
    for(int i = 0; i < book.size(); i++)
    {
        if(book[i] == this->borrwing[0].right(this->borrwing[0].size()-this->borrwing[1].size()))
        {
            ui->comboBox_3->setCurrentIndex(book[i+1].toInt() - 1);
            ui->lineEdit_remarsk->setText(book[i+2]);
            this->book_cnt = i;
        }
    }
}

void bor_mod_dialog::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
                // 忽略回车键事件
                event->ignore();
            } else {
                // 对于其他按键，调用基类的keyPressEvent
                QDialog::keyPressEvent(event);
    }
}

void bor_mod_dialog::on_pushButton_5_clicked()
{
    flag = true;
    this->book[book_cnt+1] = QString::number(ui->comboBox_3->currentIndex() + 1);
    this->book[book_cnt+2] = ui->lineEdit_remarsk->text();
    this->borrwing[4] = QDate::currentDate().toString("yyyy年MM月dd日");
    this->student[4] = QString::number(this->student[4].toUInt() - 1);
    this->close();
}
